package com.cs.tools.service.impl;

import com.cs.tools.service.IEmailService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Slf4j
public class EmailServiceImpl implements IEmailService {


    @Value("${spring.mail.username}")
    private String from;

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public void sendEmail(String to, String subject, String content) {

        SimpleMailMessage smm = new SimpleMailMessage();
        smm.setSubject(subject);
        smm.setText(content);
        smm.setTo(to);
        smm.setFrom(from);
        smm.setSentDate(new Date());
        javaMailSender.send(smm);
        log.debug("时间:{}发送一条邮件给{}成功",new Date(),subject);
    }
}
